﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AirTickets;
using System.Collections;

namespace AirTickets
{
    public partial class BilleteForm : Form
    {
        Billete _billete;

        internal  BilleteForm(Billete billete)
        {
            ListaDeVuelos vuelos = new ListaDeVuelos();

            _billete = billete;
            InitializeComponent();
            lbEstado.DataBindings.Clear();
            lbEstado.DataBindings.Add(new Binding("Text", _billete, "Estado"));

            cbVuelos.DataSource = vuelos.ToList<Vuelo>();
            cbVuelos.SelectedItem = _billete.Vuelo;

            cbAsientos.SelectedItem = _billete.Asiento;
        }

       
        private void BilleteForm_Load(object sender, EventArgs e)
        {
            tbXML.Text = _billete.GetXML();
            cbAsientos.DataBindings.Add(new Binding("SelectedItem", _billete, "Asiento"));
            cbVuelos.DataBindings.Add(new Binding("SelectedItem", _billete, "Vuelo"));
        }

        private void cbVuelos_SelectedIndexChanged(object sender, EventArgs e)
        {
            _billete.Vuelo = ((Vuelo)cbVuelos.SelectedItem);
            cbAsientos.DataSource = ((Vuelo)cbVuelos.SelectedItem).AsientosDisponibles();
            cbAsientos.DisplayMember = "DescriptorAsiento";
        }

        private void btnReservar_Click(object sender, EventArgs e)
        {
            _billete.Reservar();
            this.DialogResult = DialogResult.OK;
        }

        private void cbAsientos_SelectedIndexChanged(object sender, EventArgs e)
        {
            _billete.Asiento = (Asiento)cbAsientos.SelectedItem;
        }

        private void tbViajero_Leave(object sender, EventArgs e)
        {
            _billete.Pasajero = tbViajero.Text;
        }
    }
}
